home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-03
/
qbasicpg.zip
/
DESSERT.BAS
< prev
next >
Wrap
BASIC Source File
|
1989-08-31
|
2KB
|
48 lines
' DESSERT.BAS
' This program contains two logic errors. Can you find them?
' declare GetData subprogram
DECLARE SUB GetData (array$(), num%, totalCalories%)
CLS
' print welcome message
PRINT "Welcome to the Dessert Program!"
PRINT ' get user's name
INPUT "Please enter your name: ", userName$
PRINT ' get number of desserts
PRINT "How many desserts would you like to enter, "; userName$;
INPUT num%
PRINT
DIM desserts$(num%) ' dimension string array
GetData desserts$(), num%, totalCalories% ' call subprogram
PRINT "The following is a list of "; userName$; "'s favorite desserts:"
PRINT
FOR i% = 1 TO num%
PRINT " "; desserts$(i%) ' print array contents
NEXT i%
PRINT ' print total number of calories
PRINT "The list contains a total of"; ' with number in flashing red
COLOR 20: PRINT totalCalories%; : COLOR 7
PRINT "calories!"
END
SUB GetData (array$(), num%, totalCalories%)
' The GetData subprogram gets dessert information from the user.
FOR i% = 1 TO num% ' loop num% times (passed from main program)
INPUT " Dessert name: ", array$(num%) ' get dessert name
INPUT " Calories in dessert: ", calories% ' get calories
PRINT
totalCalories% = calories% ' keep running total
NEXT i%
END SUB ' return array$ and totalCalories% to main program